package com.edu.app.service.impl.core;

import com.edu.app.bean.core.SysCustomer;
import com.edu.app.bean.core.SysTenant;
import com.edu.app.bean.core.popup.CustomersPop;
import com.edu.app.bean.virtualbean.ObsoleteCustomer;
import com.edu.app.mapper.core.SysCustomerMapper;
import com.edu.app.mapper.core.popup.CustomersPopMapper;
import com.edu.app.service.impl.SysBaseServiceImpl;
import com.edu.app.service.sys.core.SysCustomerService;
import com.edu.app.threadlocal.TenantContext;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCustomerServiceImpl extends SysBaseServiceImpl<SysCustomer,SysCustomerMapper> implements SysCustomerService {
    @Autowired
    private SysCustomerMapper sysCustomerMapper;

    @Autowired
    private CustomersPopMapper customersPopMapper;


    @Override
    public Integer importCustomers(String data){
        return sysCustomerMapper.importCustomers(data);
    }

    @Override
    public Integer obsoleteCustomer(Integer id) {
        return sysCustomerMapper.obsoleteCustomer(id);
    }

    @Override
    public PageInfo  getObsoleteCustomers(Integer currentPage, Integer pageSize, String order, String seq) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<ObsoleteCustomer> list = sysCustomerMapper.getObsoleteCustomers(order, seq);

        PageInfo<ObsoleteCustomer> pageInfo = new PageInfo<ObsoleteCustomer>(list);
        return pageInfo;
    }



    @Override
    public List<CustomersPop> getCustomersPop(){
        List<CustomersPop> customersPops = customersPopMapper.getCustomersPop();
        return customersPops;
    }

    @Override
    public List<CustomersPop> getNotAssignedCustomersPop(){
        List<CustomersPop> customersPops = customersPopMapper.getNotAssignedCustomersPop();
        return customersPops;
    }

    @Override
    public PageInfo  getCustomer(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<SysCustomer> list = sysCustomerMapper.getCustomer();

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public PageInfo  getPoCustomer(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<SysCustomer> list = sysCustomerMapper.getPoCustomer();

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public List<SysCustomer> searchCustomer(String name){
        SysTenant sysTenant = (SysTenant) TenantContext.getCurrentTenant();
        return sysCustomerMapper.searchCustomer(name,sysTenant.getId());
    }

    @Override
    public PageInfo  getPoCustomerToday(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<SysCustomer> list = sysCustomerMapper.getPoCustomerToday();

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public PageInfo  getPoCustomerAssigned(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<SysCustomer> list = sysCustomerMapper.getPoCustomerAssigned();

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public PageInfo  getPoCustomerNotAssigned(Integer currentPage, Integer pageSize) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        PageHelper.startPage(currentPage, pageSize, true);

        List<SysCustomer> list = sysCustomerMapper.getPoCustomerNotAssigned();

        PageInfo<SysCustomer> pageInfo = new PageInfo<SysCustomer>(list);
        return pageInfo;
    }

    @Override
    public List<SysCustomer> getCustomerByChannelTag(String channel_tag, Integer number){
        return sysCustomerMapper.getCustomerByChannelTag(channel_tag, number);
    }

    @Override
    public Integer getCustomerNoByChannelTag(String channel_tag){
        return sysCustomerMapper.getCustomerNoByChannelTag(channel_tag);
    }
}